package org.example.struct.array;

import com.alibaba.fastjson.JSON;

/**
 * @author liyishan
 * @date 2023/8/22 10:31
 * @apiNote
 */

public class Test01299ReplaceElements {
    public static void main(String[] args) {
        int[] arr = new int[]{17,18,5,4,6,1};
        int[] res =test(arr);
        System.out.println(JSON.toJSON(res));
    }

    public static int[] test(int[] arr) {
        int n = arr.length;
        int[] res = new int[n];
        int max = arr[n-1];
        for(int i = n-1; i>=0;i--){
            if(i==n-1){
                res[i] = -1;
            }else{
                res[i] = max;
            }
            max = Math.max(max,arr[i]);

        }
        return res;
    }

}
